package com.JZ.QM.service.impl;

import com.JZ.QM.common.entity.ProductLibraryIncomeEntity;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.JZ.QM.common.utils.PageUtils;
import com.JZ.QM.common.utils.Query;

import com.JZ.QM.common.dao.ProductLibraryInfoDao;
import com.JZ.QM.common.entity.ProductLibraryInfoEntity;
import com.JZ.QM.service.ProductLibraryInfoService;

import javax.annotation.Resource;

/**
 *
 *
 * @author lyp
 * @email lyp@gmail.com
 * @date 2020-06-14 11:19:36
 */
@Service("productLibraryInfoService")
public class ProductLibraryInfoServiceImpl extends ServiceImpl<ProductLibraryInfoDao, ProductLibraryInfoEntity> implements ProductLibraryInfoService {
    @Resource
    ProductLibraryInfoDao productLibraryInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) throws Exception {
        IPage<ProductLibraryInfoEntity> page = this.page(
                new Query<ProductLibraryInfoEntity>().getPage(params),
                new QueryWrapper<ProductLibraryInfoEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 根据产品代码获取产品的名称
     * @param proTsCode 产品代码
     * @return
     */
    @Override
    public String getProName(String proTsCode) {
        //条件构造器
        QueryWrapper queryWrapper=new QueryWrapper();
        //备选库基本信息
        ProductLibraryInfoEntity productLibraryInfoEntity=new ProductLibraryInfoEntity();

        queryWrapper.eq("pro_ts_code",proTsCode);

        productLibraryInfoEntity=productLibraryInfoDao.selectOne(queryWrapper);
        return productLibraryInfoEntity.getProName();

    }

    /**
     * 根据产品代码获得产品id
     * @param proTsCode
     * @return
     */
    @Override
    public Long getProId(String proTsCode) {
        //构造查询器
        QueryWrapper<ProductLibraryInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pro_ts_code",proTsCode);
        //备选库信息实体
        ProductLibraryInfoEntity productLibraryInfoEntity = new ProductLibraryInfoEntity();

        productLibraryInfoEntity = productLibraryInfoDao.selectOne(queryWrapper);

        return productLibraryInfoEntity.getProId();
    }

    /**
     * 根据产品代码获得产品类型
     * @param proId
     * @return 1 是股票  0 是基金
     */
    @Override
    public Integer getProType(Long proId) {
        //产品类型
        Integer proType = 0;
        //构造查询器
        QueryWrapper<ProductLibraryInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pro_id",proId);
        //备选库信息实体
        ProductLibraryInfoEntity productLibraryInfoEntity = new ProductLibraryInfoEntity();

        productLibraryInfoEntity = productLibraryInfoDao.selectOne(queryWrapper);
        //1 是股票  0 是基金
        if(productLibraryInfoEntity.getIsShare() == 1){
            proType = 1;
        }else {
            proType = 0;
        }

        return proType;
    }

}